//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.Validators
{
    #region Using Directives
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    #endregion

    /// <summary>
    /// 
    /// </summary>
    public enum ValidateBehavior
    {
        /// <summary>
        /// 
        /// </summary>
        Contain,
        /// <summary>
        /// 
        /// </summary>
        DoesNotContain
    }

    /// <summary>
    /// 
    /// </summary>
    public class BindingValidator
    {
        /// <summary>
        /// Gets or sets the Activity Element Name.
        /// </summary>
        public string ActivityElementName { get; set; }

        /// <summary>
        /// Gets or sets the Validate behavior.
        /// </summary>
        public ValidateBehavior BehaviorValidator { get; set; }

        /// <summary>
        /// Contructor.
        /// </summary>
        /// <param name="activityElementName"></param>
        /// <param name="validateBehavior"></param>
        public BindingValidator(string activityElementName, ValidateBehavior validateBehavior)
        {
            this.ActivityElementName = activityElementName;
            this.BehaviorValidator = validateBehavior;
        }

        /// <summary>
        /// This function is used to validate the bindings of the Activity 
        /// with the passed in Activity name.
        /// </summary>
        /// <param name="checkName">Validate against name.</param>
        /// <returns>Whether IsValid or not.</returns>
        public bool ValidateBinding(string checkName)
        {
            bool isValid = false;
            if (ValidateBehavior.Contain == BehaviorValidator)
            {
                if (checkName.Contains(this.ActivityElementName))
                {
                    isValid = true;
                }
            }
            else
            {
                if (!checkName.Contains(this.ActivityElementName))
                {
                    isValid = true;
                }
            }

            return isValid;
        }
    }
}
